package com.rdd.transformation

import org.apache.spark.{SparkConf, SparkContext}

object testSortByKey {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("testSorlByKey").setMaster("local")
    val sc = new SparkContext(conf)

    val txt = sc.textFile("src\\main\\scala\\testTxt.txt")
    val value = txt.flatMap(_.split(" ")).map(x => (x, 1)).reduceByKey((x, y) => (x + y))

    /**
     * sortByKey
     */
    value.sortByKey(false).foreach(println)

    /**
     * sortBy
     */
    value.sortBy(_._1, false).foreach(println)
    value.sortBy((x) => x._2, false).foreach(println)

    value.foreach(println)

    sc.stop()
  }

}
